
package com.jz.community.moduleshopping.confirmOrder.adapter;

import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jz.community.moduleshopping.R;
import com.jz.community.moduleshopping.confirmOrder.bean.OrderCouponInfo;
import com.jz.community.moduleshopping.goodsDetail.adapter.GoodsCouponAdapter;

import java.util.List;


public class ShopCouponListAdapter extends BaseQuickAdapter<OrderCouponInfo.MerchantCouponsBean, BaseViewHolder> {
    private GoodsCouponAdapter goodsCouponAdapter;

    private ShopCouponListener shopCouponListener;

    public void setShopCouponListener(ShopCouponListener shopCouponListener) {
        this.shopCouponListener = shopCouponListener;
    }

    public ShopCouponListAdapter(@Nullable List<OrderCouponInfo.MerchantCouponsBean> data) {
        super(R.layout.shop_coupon_layout, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, OrderCouponInfo.MerchantCouponsBean item) {
        RecyclerView shop_coupon_rv = helper.getView(R.id.shop_coupon_rv);

        LinearLayoutManager main_layoutManager = new LinearLayoutManager(mContext);
        shop_coupon_rv.setLayoutManager(main_layoutManager);
        goodsCouponAdapter = new GoodsCouponAdapter(item.getCouponList());
        goodsCouponAdapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN);//加载动画
        shop_coupon_rv.setAdapter(goodsCouponAdapter);
        goodsCouponAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                shopCouponListener.setResultOrderCouponData(position,goodsCouponAdapter);
            }
        });
        goodsCouponAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                if (view.getId() == R.id.coupon_gt_click_tv) {
                    shopCouponListener.setResultOrderCouponData(position,goodsCouponAdapter);
                }
            }
        });

    }

    public interface ShopCouponListener {
        void setResultOrderCouponData(int position, GoodsCouponAdapter goodsCouponAdapter);
    }

    @Override
    public int getItemCount() {
        return super.getItemCount();
    }
}

